//
//  fenLeiDetailShaiXuanCollectionTableViewCell.m
//  Experss
//
//  Created by Chen on 2017/8/3.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "fenLeiDetailShaiXuanCollectionTableViewCell.h"

#import "fenLeiDetialCellCollectionViewCell.h"

#import "FenleiShaixuanSmallModel.h"

@interface fenLeiDetailShaiXuanCollectionTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

/**  */
@property (nonatomic , strong) UICollectionView *collectionView;


@end

@implementation fenLeiDetailShaiXuanCollectionTableViewCell

-(void)setDataArray:(NSArray *)dataArray{

    _dataArray = dataArray;
    [self.collectionView reloadData];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.dataArray = [NSArray array];
        
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    CGFloat width = (300 - 4 * 10) / 3.0- 0.01;
    layout.itemSize = CGSizeMake(width, 50);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.bounces = NO;
    self.collectionView.scrollEnabled = NO;
    
    [self.collectionView registerClass:[fenLeiDetialCellCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    [self.contentView addSubview:self.collectionView];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    fenLeiDetialCellCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    FenleiShaixuanSmallModel *model = self.dataArray[indexPath.row];
    
    cell.model = model;
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    FenleiShaixuanSmallModel *model = self.dataArray[indexPath.row];
    
    model.isSelect = !model.isSelect;
    
    
    [self.collectionView reloadData];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.collectionView.frame = self.bounds;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
